#include <bits/stdc++.h>
using namespace std;


const int N = 105, M = 26;

vector<int> pre[N];

char p[N], s[N];



int main(int argc, char const *argv[])
{
    int t;
    scanf("%d", &t);
    for (int kk=0; kk<t; ++kk) {
        scanf("%s%s", p, s);
        int len = strlen(s);
        int lenp = strlen(p);
        int b[26];
        memset(b, 0, sizeof b);
        for (int i=0; i<lenp; ++i) {
            b[p[i]-'a'] ++;    
        }
        bool found = false;
        for (int i=0; i<len; ++i)
        for (int j=i; j<len; ++j) {
            int a[26];
            memset(a, 0, sizeof a);
            
            for (int k=i; k<=j; ++k) {
                a[s[k]-'a'] ++;
            }

            bool suc = true;
            for (int k=0; k<26; ++k) {
                if (a[k] != b[k]) {
                    suc = false;
                    break;
                }
            }
            if (suc) {
                found = true;
                break;
            }
        }
        printf("%s\n", found? "YES" : "NO");
    }



    return 0;
}
